#include <iostream>
#include <string>

using namespace std;

class Base
{
public:
    virtual string type(void)
    {
        return "Base";
    }
};

class Derived : public Base
{
public:
    virtual string type(void)
    {
        return "Derived";
    }

    void printf()
    {
        cout << "I'm a Derived." << endl;
    }
};

class Child : public Base
{
public:
    virtual string type(void)
    {
        return "Child";
    }
};

void test(Base* b)
{
    /* 危险的转换方式 */
    // Derived* d = static_cast<Derived*>(b);

    if ( b->type() == "Derived" )
    {
        Derived* d = static_cast<Derived*>(b);

        d->printf();
    }

    // cout << dynamic_cast<Derived*>(b) << endl;
}

int type_recog_test(void)
{
    Base a;
    Derived b;
    Child c;

    test(&a);
    test(&b);
    test(&c);

    return 0;
}
